var ue = UE.getEditor('myEditor', {
        toolbars: [
            [
                'fullscreen', //全屏
                'undo', //撤销
                'redo', //重做
                'bold', //加粗
                'italic', //斜体
                'underline', //下划线
                'indent', //首行缩进
                'fontfamily', //字体
                'fontsize', //字号
                'paragraph', //段落格式
                'forecolor', //字体颜色
                'backcolor', //背景色
                'justifyleft', //居左对齐
                'justifycenter', //居中对齐
                'justifyright', //居右对齐
                'removeformat', //清除格式
                'link', //超链接
                'unlink', //取消链接
                'lineheight', //行间距
                'horizontal', //分隔线
                'simpleupload', //单图上传
                // 'spechars', //特殊字符
                // 'searchreplace', //查询替换
                'preview', //预览
                'cleardoc', //清空文档

            ]
        ],
        //focus时自动清空初始化时的内容
        autoClearinitialContent: true,
        //关闭字数统计
        wordCount: false,
        //关闭elementPath
        elementPathEnabled: false,
        //默认的编辑区域高度
        initialFrameHeight: 310,
        // 防止div赋值到编辑器变成P
        allowDivTransToP: false,
        //是否自动保存
        enableAutoSave: false
            //更多其他参数，请参考ueditor.config.js中的配置项
    })
    $(function() {
        var winHeight = $(window).height();
        $(".content-wrapper").css("minHeight", winHeight - 52);

        var wrapper = new Vue({
            el: '.wrapper',
            data: {
                managetype: 1, //1:列表，2：新增
                edittype: 1, //1:商品信息，2：图片，3：详情
                goodsstate: 1, //1:出售中，2：售罄的
                editline: '',
                editindex: '',
                goods: {
                    id: '',
                    imgs: [],
                    code: '',
                    name: '',
                    type: '',
                    price: '',
                    norms: '',
                    unit: '',
                    detail: '',
                    sellnum: 0,
                    leftnum: 0,
                    cansellnum: 0

                },
                goodslist: [{
                    id: '1',
                    imgs: ['../img/renqi1.png', '../img/renqi2.png'],
                    code: '我是编码1',
                    name: '我是商品1',
                    type: '红茶',
                    price: '88.98',
                    norms: '200g',
                    unit: '罐',
                    detail: '',
                    sellnum: '33355',
                    leftnum: '8',
                    cansellnum: '8'
                },{
                    id: '2',
                    imgs: ['../img/renqi2.png', '../img/renqi1.png'],
                    code: '我是编码2',
                    name: '我是商品2',
                    type: '红茶',
                    price: '88.98',
                    norms: '200g',
                    unit: '罐',
                    detail: '',
                    sellnum: '33355',
                    leftnum: '0',
                    cansellnum: '0'
                },{
                    id: '3',
                    imgs: ['../img/rose4.JPG', '../img/renqi2.png'],
                    code: '我是编码3',
                    name: '我是商品3',
                    type: '红茶',
                    price: '66.98',
                    norms: '200g',
                    unit: '罐',
                    detail: '',
                    sellnum: '35',
                    leftnum: '5',
                    cansellnum: '5'
                }]

            },
            components: {
                mainHead,
                mainSidebar
            },
            methods: {
                changeManagetype: function(i) {
                    if (i == 2) {
                        this.resetGoods();
                    }

                    this.managetype = i;


                },
                changeEditType: function(i) {
                    this.edittype = i;

                },
                changeGoodsState:function(i){
                    this.goodsstate=i;

                },
                clickBtnAddImg: function() {
                    $("#btnAddImg").click();

                },
                save: function() {
                    if (this.goods.id == '') {
                        this.goods.id=this.goodslist.length+1;
                        this.goodslist.push(this.goods)
                    } else {

                        this.goodslist.splice(this.editindex, 1, this.goods)
                    }



                },
                edit: function(i) {
                    this.managetype = 2;
                    var obj = this.goodslist[i];
                    this.goods = obj;
                    this.editindex = i;

                },
                resetGoods: function() {
                    // this.$set(this.goods, "id", '');
                    // this.goods.imgs.splice(0,this.goods.imgs.length);
                    // this.$set(this.goods, "code", '');
                    // this.$set(this.goods, "name", '');
                    // this.$set(this.goods, "type", '');
                    // this.$set(this.goods, "price", '');
                    // this.$set(this.goods, "norms", '');
                    // this.$set(this.goods, "unit", '');
                    // this.$set(this.goods, "detail", '');
                    // this.$set(this.goods, "sellnum", '');
                    // this.$set(this.goods, "leftnum", '');
                    // this.$set(this.goods, "cansellnum", '');
                    var goods = {
                        id: '',
                        imgs: [],
                        code: '',
                        name: '',
                        type: '',
                        price: '',
                        norms: '',
                        unit: '',
                        detail: '',
                        sellnum: 0,
                        leftnum: 0,
                        cansellnum: 0

                    }
                    this.goods = goods;



                },
                backlist: function() {
                    this.managetype = 1;
                    this.resetGoods();



                },
                computeNum:function(i,j){
                   // i表示第几个numitem，j表示加减
                   if (i==1) {
                    this.goods.sellnum=parseInt(this.goods.sellnum)+j;

                   }else if(i==2){
                    this.goods.leftnum=parseInt(this.goods.leftnum)+j;

                   }else{
                    this.goods.cansellnum=parseInt(this.goods.cansellnum)+j;

                   }
                },
                del:function(index){
                    this.goodslist.splice(index, 1);

                },
                showOrHideTr:function(leftnum,canselnum){
                    if (this.goodsstate==1) {
                        if (leftnum>0) {
                            return true;
                        }else{
                            return false;
                        }
                    }else{
                        if (leftnum==0) {
                            return true;
                        }else{
                            return false;
                        }

                    }
                }

            }
        })


    })